package com.darren.cloud;

package com.darren.monday;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.query.SQLQuery;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;

public class CodeGenerator {


    public static final String dbUrl = "jdbc:mysql://localhost:3308/eams202409?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&allowMultiQueries=true";
    public static final String userName = "root";
    public static final String password = "root";
    public static final Path outputPath = Paths.get(System.getProperty("user.dir"),"src","main","java");
    public static final Path mapperXmlPath = Paths.get(System.getProperty("user.dir"),"src","main","resources","mapper");

    public static void main(String[] args) {

        FastAutoGenerator.create(dbUrl, userName, password)
                .globalConfig(builder -> builder
                        .disableOpenDir()
                        .author("Monday")
                        .outputDir(outputPath.toString())
                        .commentDate("yyyy-MM-dd HH:mm:ss")
                        .enableSwagger()
                        .enableSpringdoc()
                )
                .dataSourceConfig(builder ->
                        builder.databaseQueryClass(SQLQuery.class)
                                .typeConvert(new MySqlTypeConvert())
                                .dbQuery(new MySqlQuery())
                )
                .packageConfig(builder -> builder
                        .parent("com.darren")
                        .moduleName("monday")
                        .controller("controller") // 设置 Controller 包名
                        .entity("model")    // 设置 Entity 包名
                        .mapper("mapper")   // 设置 Mapper 包名
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper")  // 设置 Mapper XML 包名
                        .pathInfo(Collections.singletonMap(OutputFile.xml, mapperXmlPath.toString()))
                )
                .strategyConfig(builder -> builder
                                .addInclude("arc_box_number")
                                .entityBuilder()
                                .enableFileOverride()
                                .enableLombok()
                                .javaTemplate("generator/templates/entity.java")
                                .serviceBuilder()
                                .enableFileOverride()
                                .serviceTemplate("generator/templates/service.java")
                                .serviceImplTemplate("generator/templates/serviceImpl.java")
                                .controllerBuilder()
//                        .enableFileOverride()
                                .template("generator/templates/controller.java")
                                .enableRestStyle()
                                .mapperBuilder()
                                .enableFileOverride()
                                .mapperTemplate("generator/templates/mapper.java")
                                .mapperXmlTemplate("generator/templates/mapper.xml")
                                .enableBaseResultMap()
                                .enableBaseColumnList()
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();


    }


}
